<template>
  <div>
    <van-nav-bar title="修改昵称" @click-left="goback">
      <template #left>
        <van-icon name="arrow-left" size="18" />
      </template>
    </van-nav-bar>
    <div class="content">
      <div class="zi">用户名:</div>
      <input class="user_name" v-model="username" type="text" />
      <div class="font">
        以英文字母或汉字开头，限4-16个字符，一个汉字为两个字符
      </div>
      <div class="queren" @click="confirm">确认</div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
export default {
  name: "usernameedit",
  data() {
    return {
      username: "",
      update_username_id: JSON.parse(localStorage.getItem("waimai")).user_id,
    };
  },
  created() {
    // console.log(this.$route.params)
    this.username = this.$route.params.username;
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    confirm() {
      // console.log(this.username);
      if (this.username == undefined) {
        Toast("用户昵称不能为空")
        return
      }
      var tmp_obj = {
        username: this.username,
        update_username_id: this.update_username_id
      }
      this.axios({
        method: "post",
        url: "http://localhost:3000/update_information",
        data: tmp_obj,
      })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style scoped>
.van-icon {
  color: black;
}

.content {
  width: 94%;
  margin: auto;
}

.zi,
.font {
  height: 40px;
  line-height: 40px;
}

.font {
  font-size: 13px;
  border-top: 1px solid grey;
}

/deep/.van-nav-bar__left {
  padding-left: 10px;
}

.queren {
  width: 100%;
  margin: auto;
  background-color: rgb(218, 218, 9);
  text-align: center;
  height: 30px;
  line-height: 30px;
}

.user_name {
  width: 100%;
  border: none;
  background-color: rgb(231, 231, 231);
}
</style>